In [1]:
import IPython
import ipywidgets
import numpy as np
import image_attendant as imat
import jpy_canvas
In [6]:
image = imat.read('images/mini_2.jpg')
image_b = imat.rebin(image, 0.25)
H,W = image.shape[:2]
L = 20
L2 = L*2 + 1
In [7]:
wid_img = jpy_canvas.Canvas(image)
wid_sub = jpy_canvas.Canvas(image_b)
wid_img.width = W
wid_img.height = H
# wid_sub.width = L2*3
# wid_sub.height = L2*3
wid_box = ipywidgets.HBox([wid_img, wid_sub])
wid_box
In [14]:
wid_sub.width=300
In [12]:
wid_sub.layout.border='black'
In [11]:
def work_function(wid, event):
"""Mouse motion event handler
"""
i = event['canvasX']
i0 = i-L
i1 = i+L+1
j = event['canvasY']
j0 = j-L
j1 = j+L+1
if i0 < 0:
i0 = 0
if j0 < 0:
j0 = 0
crop = wid.data[j0:j1, i0:i1]
# print(i0,i1,j0,j1)
# print(crop.shape)
with wid_sub.hold_sync():
wid_sub.data = crop
wid_sub.width = crop.shape[1]*5
wid_sub.height = crop.shape[0]*5
wid_img.register_move(work_function)
In [ ]: